using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerTouchingWallState : PlayerState
{
    public PlayerTouchingWallState(Player player, PlayerMoveData playerData, StateMachine stateMachine, string animBoolName) : base(player, playerData, stateMachine, animBoolName)
    {
        stateType = StateType.TouchingWall;
    }

    public override void Enter()
    {
        base.Enter();

        player.JumpState.ResetJumpCount();
    }

    public override void LogicUpdate()
    {
        base.LogicUpdate();

        if (isTouchingWall && jumpInput && xInput == player.FacingDirection)
        {
            stateMachine.ChangeState(player.WallJumpState);
        }
        else if (isTouchingWall && !isTouchingLedge && !isGrounded)
        {
            stateMachine.ChangeState(player.LedgeClimbState);
        }
        else if (!grabInput && isGrounded)
        {
            stateMachine.ChangeState(player.IdleState);
        }
        else if (!isTouchingWall || !grabInput && xInput != player.FacingDirection)
        {
            stateMachine.ChangeState(player.InAirState);
        }
    }

    public override void OnCheck()
    {
        base.OnCheck();

        isGrounded = player.CheckLeftFootIfGrounded() || player.CheckRightFootIfGrounded();
        isTouchingWall = player.CheckIsTouchingWall();
        isTouchingLedge = player.CheckIsTouchingLedge();

        if (isTouchingWall && !isTouchingLedge)
        {
            player.LedgeClimbState.SetdetecedPos(player.transform.position);
        }
    }
}
